//
//  InformationHelp.m
//  MGLOL盒子
//
//  Created by lanou3g on 15/12/1.
//  Copyright © 2015年 张明. All rights reserved.
//

#import "InformationHelp.h"
#import "Information.h"
#define inforURL @"http://qt.qq.com/static/pages/news/phone/c12_list_1.shtml"
#import "AFHTTPSessionManager.h"
static InformationHelp *inforHelp = nil;
@interface InformationHelp ()


@end

@implementation InformationHelp
- (void)getInforListDataWithUrl:(NSString *)url successData:(void (^)(NSMutableArray *array))success fail:(void (^)(NSError *err))fail {
    //判断URL是否为空
    if (!url) {
        NSError *err = [NSError errorWithDomain:@"Url为空" code:1 userInfo:nil];
        fail(err);
        return;
    }
        //遍历数组，封装数据
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
        [manager GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            NSLog(@"%@",responseObject);
            NSArray *arr = responseObject[@"list"];
            _allDataMutableArr = [[NSMutableArray alloc]init];
            for (NSDictionary* d in arr) {
                Information *model = [[Information alloc]init];
           [model setValuesForKeysWithDictionary:d];
            [_allDataMutableArr addObject:model];
                NSLog(@"-------%@",model.title);
            }
            success(_allDataMutableArr);
//            NSLog(@"!!!!!!!!%@",_allDataMutableArr);
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"%@",error);
        }];
}
//-(NSMutableArray *)allDataMutableArr{
//    if (!_allDataMutableArr) {
//        _allDataMutableArr = [NSMutableArray array];
//    }
//    return _allDataMutableArr;
//}
+(instancetype)shareWithHelpData {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        inforHelp = [[InformationHelp alloc]init];
    });

    return inforHelp;
}
@end
